package cn.sh.ideal.web.monitoring.alarm.management.warning.notice.controller;


import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.PropertySource;
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.client.RestTemplate;

import cn.sh.ideal.web.monitoring.alarm.management.warning.notice.entity.WarnNoticeEntity;

@Controller
@PropertySource(value = {"classpath:jdbc.properties"})
@RequestMapping(value = "/get")
public class WarningNoticeDataController {
	
	
	@Bean
	public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() {
		return new PropertySourcesPlaceholderConfigurer();
	}
	
	private RestTemplate rs = new RestTemplate();
	
	@Value("${server_address}")
	private String serverAddress;
	
	/**
	 * 查询报警监控的信息
	 * @return 
	 */
	@RequestMapping(value = "/getWarnNtticeInfo", method = RequestMethod.POST)
	@ResponseBody
	public String getWarningNotice(@RequestBody WarnNoticeEntity parameter){
		
		String monitoringStatus = parameter.getMonitoringStatus();
		String monitoringIndex = parameter.getMonitoringIndex();
		String idexKpi = parameter.getIdexKpi();
		String earlyWarningLevel = parameter.getEarlyWarningLevel();
		String startTime = parameter.getStartTime();
		String endTime = parameter.getEndTime();
		int size =  parameter.getSize();
		int page = parameter.getPage();
		
		
		String url = serverAddress +"/selectWarnNtticeInfo?monitoringStatus="+ monitoringStatus
				+"&monitoringIndex=" + monitoringIndex +"&idexKpi=" + idexKpi
				+"&earlyWarningLevel=" + earlyWarningLevel + "&startTime=" + startTime
				+"&endTime=" + endTime + "&size="+size+"&page="+page;
		System.out.print(url);
		HttpHeaders header = new HttpHeaders();
		MediaType type = MediaType.parseMediaType("application/json;charset=UTF-8");
		header.setContentType(type);
		HttpEntity<String> entity = new HttpEntity<>(new String(), header);
		ResponseEntity<String> exchange = rs.exchange(url,HttpMethod.GET, entity, String.class);
		String reult = exchange.getBody();
		return reult;
	}
	
	/**
	 * 查询报警监控的信息
	 * @return 
	 */
	@RequestMapping(value = "/getAlarmCount", method = RequestMethod.POST)
	@ResponseBody
	public String getAlarmCount(@RequestBody WarnNoticeEntity parameter){
		
		String monitoringStatus = parameter.getMonitoringStatus();
		String monitoringIndex = parameter.getMonitoringIndex();
		String idexKpi = parameter.getIdexKpi();
		String earlyWarningLevel = parameter.getEarlyWarningLevel();
		String startTime = parameter.getStartTime();
		String endTime = parameter.getEndTime();
		
		
		String url = serverAddress +"/getAlarmCount?monitoringStatus="+ monitoringStatus
				+"&monitoringIndex=" + monitoringIndex +"&idexKpi=" + idexKpi
				+"&earlyWarningLevel=" + earlyWarningLevel + "&startTime=" + startTime
				+"&endTime=" + endTime;
		
		HttpHeaders header = new HttpHeaders();
		MediaType type = MediaType.parseMediaType("application/json;charset=UTF-8");
		header.setContentType(type);
		HttpEntity<String> entity = new HttpEntity<>(new String(), header);
		ResponseEntity<String> exchange = rs.exchange(url,HttpMethod.GET, entity, String.class);
		String reult = exchange.getBody();
		return reult;
	}
	
	
	/**
	 * 查询报警监控的信息
	 * @return 
	 */
	@RequestMapping(value = "/getWarnEchart", method = RequestMethod.POST)
	@ResponseBody
	public String getWarnEchart(@RequestBody WarnNoticeEntity parameter){
		
		String monitoringStatus = parameter.getMonitoringStatus();
		String monitoringIndex = parameter.getMonitoringIndex();
		String idexKpi = parameter.getIdexKpi();
		String earlyWarningLevel = parameter.getEarlyWarningLevel();
		String startTime = parameter.getStartTime();
		String endTime = parameter.getEndTime();
		
		
		String url = serverAddress +"/getWarnEchart?monitoringStatus="+ monitoringStatus
				+"&monitoringIndex=" + monitoringIndex +"&idexKpi=" + idexKpi
				+"&earlyWarningLevel=" + earlyWarningLevel + "&startTime=" + startTime
				+"&endTime=" + endTime;
		
		HttpHeaders header = new HttpHeaders();
		MediaType type = MediaType.parseMediaType("application/json;charset=UTF-8");
		header.setContentType(type);
		HttpEntity<String> entity = new HttpEntity<>(new String(), header);
		ResponseEntity<String> exchange = rs.exchange(url,HttpMethod.GET, entity, String.class);
		String reult = exchange.getBody();
		return reult;
	}
	
	/**
	 * 搜索部分下拉框的值
	 * @return 
	 */
	@RequestMapping(value = "/getSelectOptionValue", method = RequestMethod.POST)
	@ResponseBody
	public String getSelectOptionValue(){

		String url = serverAddress +"/getSelectOptionValue";
		
		HttpHeaders header = new HttpHeaders();
		MediaType type = MediaType.parseMediaType("application/json;charset=UTF-8");
		header.setContentType(type);
		HttpEntity<String> entity = new HttpEntity<>(new String(), header);
		ResponseEntity<String> exchange = rs.exchange(url,HttpMethod.GET, entity, String.class);
		String reult = exchange.getBody();
		return reult;
	}
	
}
